/**
 * 活动表字段
*/
import { model, Schema } from 'mongoose';
import { ActivityStatus } from '@/enums/activityEnums';
import { PhotoModel } from '../models/photo.model';
import { ChatRoomModel } from '../models/chatRoom.model';
import { LocationSchema } from './location.schema';

export const ActivitySchema = new Schema({
  /**
   * 创建活动的用户id
  */
  creator: {
    type: Schema.Types.ObjectId,
    required: true,
    ref: 'users'
  },
  /**
   * 活动标题
  */
  title: {
    type: String,
    required: true
  },
  /**
   * 活动描述
  */
  description: {
    type: String,
    required: false
  },
  /**
   * 活动图片
  */
  images: [{
    required: false,
    type: Schema.Types.ObjectId,
    ref: PhotoModel
  }],
  /**
   * 活动地点
  */
  location: {
    type: LocationSchema,
    required: false
  },
  /**
   * 活动状态
  */
  status: {
    type: String,
    enum: Object.values(ActivityStatus),
    default: ActivityStatus.unreviewed
  },
  /**
   * 活动参与人数限制
  */
  participateLimit: {
    type: Number,
    required: false
  },
  /**
   * 聊天室id
  */
  chatRoom: {
    required: true,
    type: Schema.Types.ObjectId,
    ref: ChatRoomModel
  }
}, {
  timestamps: true
});

// 活动
export const ActivityModel = model('activities', ActivitySchema);